subroutine r1ai_t2efmi_iefam(r1, t2, iabci,& 
               icore, fact)
!
use mod_ioff
use mod_orbit
use mod_size 
use mod_iop
implicit none
!
real*8, intent(inout) :: fact
real*4, intent(in) :: r1(*)
real*4, intent(in) :: iabci(*)
!
real*4, intent(inout) :: t2(*), icore(*)
!
integer :: i, j, a, b, nsize
integer :: i0, i1, i2, i3
integer, external :: irpdso
real*8, external :: dnrm2
!this is to do r1(ai) = r1(ai) -0.5*t2(ef,mi)*<ef||am>
!
i0 = 1
i1 = i0 + nvvoo*isd
i2 = i1 + nvvvo*isd
!===AA
!<EF||AM>*T2(EF,MI)
call isymtrso(iabci(ioi5(1)), icore(i1), vrta, vrta, 0, 0, vrta, popa, 1, 1, 1) 
call iexpso(t2(ioi3(1)), icore(i0), vrta, vrta, 0, 0, popa, popa, 0, 1, 1) 
call VpqrmVpqrn_to_Vmn(icore(i1), icore(i0), 1, 1, vrta, vrta, 0, &
                      popa, vrta, popa, r1(ifvo(1)), 1, fact*2.d0)
nsize = irpdso(1, vrta, popa, 1)
!write(6,*)'norm of aa 1', dnrm2(nsize, r1(ifvo(1)), 1)
!<eF||Am>*T2(eF,mI) = - <Fe|Am>*T2(Fe,Im)
call isymtrso(iabci(ioi5(2)), icore(i1), vrta, vrtb, 1, 0, vrta, popb, 1, 1, 1) 
call isymtrso(t2(ioi3(2)), icore(i0), vrta, vrtb, 1, 0, popa, popb, 1, 1, 1) 
call VpqrmVpqrn_to_Vmn(icore(i1), icore(i0), 1, 1, vrta, vrtb, 1, &
                      popb, vrta, popa, r1(ifvo(1)), 1, -fact*2.d0)
nsize = irpdso(1, vrta, popa, 1)
!write(6,*)'norm of aa 2', dnrm2(nsize, r1(ifvo(1)), 1)
!===BB
!<ef||am>*T2(ef,mi)
call isymtrso(iabci(ioi5(3)), icore(i1), vrtb, vrtb, 0, 0, vrtb, popb, 1, 1, 1)
call iexpso(t2(ioi3(3)), icore(i0), vrtb, vrtb, 0, 0, popb, popb, 0, 1, 1)
call VpqrmVpqrn_to_Vmn(icore(i1), icore(i0), 1, 1, vrtb, vrtb, 0, &
                      popb, vrtb, popb, r1(ifvo(2)), 1, fact*2.d0)
nsize = irpdso(1, vrtb, popb, 1)
!write(6,*)'norm of bb 1', dnrm2(nsize, r1(ifvo(2)), 1)
!<Ef||aM>*T2(Ef,Mi) = - <fE||aM>*T2(Ef,Mi)
call isymtrso(iabci(ioi5(4)), icore(i1), vrtb, vrta, 1, 0, vrtb, popa, 1, 1, 1)
call isymtrso(t2(ioi3(2)), icore(i0), vrta, vrtb, 1, 1, popa, popb, 1, 0, 1)
call VpqrmVpqrn_to_Vmn(icore(i1), icore(i0), 1, 1, vrtb, vrta, 1, &
                      popa, vrtb, popb, r1(ifvo(2)), 1, -fact*2.d0)
nsize = irpdso(1, vrtb, popb, 1)
!write(6,*)'norm of bb 2', dnrm2(nsize, r1(ifvo(2)), 1)
return
end
